//
//  XJ_ChangePasswordViewController.m
//  XunJieProject
//
//  Created by xue on 2018/6/8.
//  Copyright © 2018年 Soowin. All rights reserved.
//

#import "XJ_ChangePasswordViewController.h"

@interface XJ_ChangePasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *oldPasswordTF;
@property (weak, nonatomic) IBOutlet UITextField *confirmPasswordTF;
@property (weak, nonatomic) IBOutlet UITextField *newdPassTF;
@property (weak, nonatomic) IBOutlet UIButton *modifyBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *up_phoneView;

@end

@implementation XJ_ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.phoneTF.text =_userInfoModel.mobile;
}
- (void)creatMainUI{
    
    self.nav_titleLabel.text =@"修改密码";
    _modifyBtn.backgroundColor =Color_ZhuSeDiao;
    _modifyBtn.layer.cornerRadius =4;
    _modifyBtn.layer.masksToBounds =YES;
    _up_phoneView.constant =SafeAreaTopHeight;
    _oldPasswordTF.secureTextEntry =YES;
    _newdPassTF.secureTextEntry =YES;
    _confirmPasswordTF.secureTextEntry =YES;
}
- (IBAction)Click_btn:(id)sender {
    
    [self.view endEditing:YES];
    
    if (_oldPasswordTF.text.length==0) {
        ZDXAlertView *alext =[[ZDXAlertView alloc]initWithMessage:@"请输入旧密码" image:@"pop_msg_tip_xs"];
        [alext showXLAlertView];
        return;
    }
    if (_newdPassTF.text.length==0) {
        ZDXAlertView *alext =[[ZDXAlertView alloc]initWithMessage:@"请输入新密码" image:@"pop_msg_tip_xs"];
        [alext showXLAlertView];
        return;
    }
    if (_confirmPasswordTF.text.length==0) {
        ZDXAlertView *alext =[[ZDXAlertView alloc]initWithMessage:@"请确认新密码" image:@"pop_msg_tip_xs"];
        [alext showXLAlertView];
        return;
    }
    
    [self loadUserInnerResetPassword];
}
#pragma mark--修改密码接口
-(void)loadUserInnerResetPassword{
    
    NSUserDefaults * db = [NSUserDefaults standardUserDefaults];
    NSString * token = [db objectForKey:@"token"];
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:IDENTIFIER forKey:@"equipmentNo"];
    [dic setValue:STSTERMVERSION forKey:@"systemVersion"];
    [dic setValue:APPVERSION forKey:@"appVersion"];
    [dic setValue:USERID forKey:@"userId"];
    [dic setValue:token forKey:@"token"];
    
//    [dic setValue:[[_oldPasswordTF.text md5HexDigest] uppercaseString] forKey:@"oldPassword"];
//    [dic setValue:[[_newdPassTF.text md5HexDigest] uppercaseString] forKey:@"newPassword"];
//    [dic setValue:[[_confirmPasswordTF.text md5HexDigest] uppercaseString] forKey:@"confirmPassword"];
    
    [dic setValue:_oldPasswordTF.text forKey:@"oldPassword"];
    [dic setValue:_newdPassTF.text forKey:@"newPassword"];
    [dic setValue:_confirmPasswordTF.text forKey:@"confirmPassword"];
    
    
    [XJ_Utils signPost:@"/user/innerResetPassword?" parameters:dic success:^(NSInteger recode, id jsonObject) {
        
        NSDictionary * dataDic = [jsonObject objectForKey:@"data"];
        NSString * tokenStr = [dataDic objectForKey:@"token"];
        
        NSUserDefaults * db = [NSUserDefaults standardUserDefaults];
        [db setObject:[tokenStr lowercaseString] forKey:@"token"];
        [db synchronize];
        
        ZDXAlertView *alext =[[ZDXAlertView alloc]initWithMessage:@"修改成功" image:@"pop_msg_succeed_xs"];
        [alext showXLAlertView];
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
